package _28define.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;


public class Receiver {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket=new DatagramSocket(9999);
        byte[] bytes=new byte[1024];
        DatagramPacket receiverPackget=new DatagramPacket(bytes,0,bytes.length);
        datagramSocket.receive(receiverPackget);
        int length=receiverPackget.getLength();
        byte[] data=receiverPackget.getData();
        int offset= receiverPackget.getOffset();

        String msg=new String(data,offset,length);
        System.out.println("接收到了来自发送端的消息："+msg);
        datagramSocket.close();
    }
}
